#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=303;
int n,a[N],sta[N],f[N],g[N],f[N][N][N];
int main()
{
	freopen("build.in","r",stdin);
	cin>>n;int mx=0;
	cerr<<n<<endl; 
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int t=1;t<=n;t++)
	{
		memset(f,0x3f,sizeof(f));
		f[1][1][0]=a[i]==t;
		for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)for(int k=1;k<=n;k++)if(f[i][j][k]<=1e9)
		{
			for(int p=max(i,j)+1;p<=n;p++)if(a[p]!=t)
			{
				if(a[p]>t)
				{
					if(a[j]>t)
					{
						if(a[p]<=a[j]||a[p]-a[j]-1<p-j-1)continue;
						f[j][p][k+a[p]-a[j]-p+j]=max(f[j][p][k+a[p]-a[j]-p+j])
					}
				}
			}
		}
	}
	cout<<n-mx;
}
